package br.edu.ufcg.dsc.actions.resource;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.resource.Volume;
import br.edu.ufcg.dsc.services.ResourceService;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/volume.jsp")
public class FindVolumeAction extends ResourceDriven<Volume> implements Preparable, ModelDriven<Volume>{
	
	private int resourceId;
	private Volume volume;
	
	private static final long serialVersionUID = 1L;

	public void prepare() throws Exception {
		Resource resource = ResourceService.find(resourceId);
		if (resource != null)
			volume = new Volume(resource.getMarc());
		else volume = new Volume();
	}

	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}

	public Volume getVolume() {
		return volume;
	}

	public void setVolume(Volume volume) {
		this.volume = volume;
	}

	public Volume createModel() {
		return volume;
	}

	@Override
	public String execute(){		
		return SUCCESS;
	}
}
